﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
//using System.Data.Entity.Core.Objects;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GPS.DataAccessLayer
{
    public static class EFSequence
    {
        //public static int GetNextValue(this ObjectContext contexto, string SequenceName)
        //{
        //    string Connection = ConfigurationManager.ConnectionStrings["GPS_NVContext"].ConnectionString;
        //    Connection = Connection.Substring(Connection.IndexOf(@"connection string=") + 19);
        //    Connection = Connection.Remove(Connection.Length - 1, 1);
        //    using (IDbConnection con = new Oracle.ManagedDataAccess.Client.OracleConnection(Connection))
        //    {
        //        using (IDbCommand cmd = con.CreateCommand())
        //        {
        //            con.Open();
        //            cmd.CommandText = String.Format("Select {0}.nextval from DUAL", SequenceName);
        //            return Convert.ToInt32(cmd.ExecuteScalar());
        //        }
        //    }

        //}

        public static int GetNextValue( string SequenceName)
        {
            string Connection = ConfigurationManager.ConnectionStrings["GPS_NVContext"].ConnectionString;
            Connection = Connection.Substring(Connection.IndexOf(@"connection string=") + 19);
            Connection = Connection.Remove(Connection.Length - 1, 1);
            using (IDbConnection con = new Oracle.ManagedDataAccess.Client.OracleConnection(Connection))
            {
                using (IDbCommand cmd = con.CreateCommand())
                {
                    con.Open();
                    cmd.CommandText = String.Format("Select {0}.nextval from DUAL", SequenceName);
                    return Convert.ToInt32(cmd.ExecuteScalar());
                }
            }

        }
    }
}
